<?php
declare (strict_types = 1);

namespace app\admin\controller;

use app\admin\service\MarketSmCopywritingTasks as MarketSmCopywritingTasksService;
use app\admin\validate\MarketSmCopywritingTasks as MarketSmCopywritingTasksValidate;
use think\Request;

class MarketSmCopywritingTasks
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        //
    }

    /**
     * 显示创建资源表单页.
     *
     * @return \think\Response
     */
    public function create()
    {
        //
    }

    /**
     * 保存新建的资源
     *
     * @param  \think\Request  $request
     * @return \think\Response
     */
    public function save(Request $request)
    {
        //
    }

    /**
     * 显示指定的资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function read(Request $request, MarketSmCopywritingTasksService $service, MarketSmCopywritingTasksValidate $validate)
    {
        $checkData = $request->param();
        if (!$validate->scene('read')->check($checkData)) {
            return json(['code' => 1, 'message' => $validate->getError()]);
        }
        $param['id'] = $request->param('id',null);
        $arrData = $service->read($param);
        return json($arrData);
    }

    /**
     * 显示编辑资源表单页.
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * 保存更新的资源
     *
     * @param  \think\Request  $request
     * @param  int  $id
     * @return \think\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * 删除指定资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function delete($id)
    {
        //
    }

    /**
     * 批量生成社媒文案任务
     * @param Request $request
     * @param MarketSmCopywritingTasksService $service
     * @param MarketSmCopywritingTasksValidate $validate
     * @return \think\response\Json
     */
    public function batchGeneration(Request $request, MarketSmCopywritingTasksService $service, MarketSmCopywritingTasksValidate $validate){
        $checkData = $request->param();
        if (!$validate->scene('batchGeneration')->check($checkData)) {
            return json(['code' => 1, 'message' => $validate->getError()]);
        }
        $param['operator_id'] = $request->operator_id;

        $param['crypto_news_id'] =  $request->param('crypto_news_id', null);
        $param['channel_id'] =  $request->param('channel_id', null);
        $param['language_id'] =  $request->param('language_id', null);
        $param['account_group_id'] =  $request->param('account_group_id', null);
        $param['mining_machine'] =  $request->param('mining_machine', null);
        $param['cue_word'] =  $request->param('cue_word', null);
        $param['imgs'] =  $request->param('imgs', []);

        $arrData = $service->batchGeneration($param);
        return json($arrData);
    }
}
